package com.rajaev.dtu.tractor.interfaces;

import com.github.pagehelper.PageInfo;

import com.rajaev.dtu.tractor.app.service.BatteryInspectService;
import com.rajaev.dtu.tractor.domain.entity.BatteryInspectTaskDetail;
import com.rajaev.dtu.tractor.domain.entity.UserInfo;
import com.rajaev.dtu.tractor.infrastructure.base.vo.BatteryInspectVo;
import com.rajaev.dtu.tractor.infrastructure.helper.UserSecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 自动巡检
 * @Created with IDEA
 * @author: tianjie
 * @Date:2019/4/11
 * @Time:10:15
 */
@RestController
public class BatteryInspectController {

    @Autowired
    BatteryInspectService batteryInspectService;

    @Autowired
    UserSecurityUtil userSecurityUtil;

    @PostMapping("/inspection/start")
    public void startAInspectTask(HttpServletRequest request){
        UserInfo userInfo = userSecurityUtil.getLoginUser(request).getUserInfo();
        batteryInspectService.submitAInspectTask(userInfo.getId());
    }

    @GetMapping("/inspection/queryTask")
    public PageInfo<BatteryInspectVo> selectInspectVo(@RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(defaultValue = "1") Integer pageNum,HttpServletRequest request){
        return batteryInspectService.pageQueryInspectVo(request,pageSize,pageNum);
    }


    @GetMapping("/inspection/getInspectionResultById")
    public PageInfo<BatteryInspectTaskDetail> selectInspectDetail(@RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(defaultValue = "1") Integer pageNum, Integer taskId, String keyword, String orderField, Integer order){
        return batteryInspectService.pageQueryInspectDetail(pageSize, pageNum, taskId,keyword,orderField,order);
    }

}
